package servlets;
import java.util.*;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class ProductsProvider {
    private static List<Product> goods = new ArrayList<Product>();
    public Product[] getProducts()
    {
        Product[] goodsArray = null;
        goodsArray = (Product[]) goods.toArray(new Product[goods.size()]);
        return goodsArray;
    }
    public ProductsProvider()
    {
        goods.clear();

        try {

       /*     long n = DBProvider.insertRecordIntoTable("INSERT INTO Product"
                    + "(TITLE, ComplexityOfManufacturing, DimensionalSize) VALUES('newProduct',0,0)");
                      */
            ResultSet rs = DBProvider.selectRecordsFromDbUserTable("SELECT ID, TITLE from Product");

            while (rs.next()) {

                Integer id = Integer.parseInt(rs.getString("ID"));
                String title = rs.getString("TITLE");

                Product product = new Product();
                product.setId(id);
                product.setTitle(title);
                goods.add(product);

            }
        } catch (SQLException e) {

            System.out.println(e.getMessage());

        }
    }


}
